﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DepartmentSystem
{
    public partial class ForgetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = TextBox1.Text;
            string password = TextBox2.Text;

            string password2 = TextBox3.Text;
            string email = TextBox4.Text;

            string sql = "select count(*) cnt from tb_user where username = '" + username + "' and email = '" + email + "'";
            if ((int)SQLHelper.QueryScalar(sql) != 1)
            {
                Response.Write("<script>alert('请确认用户名、邮箱!')</script>");
                return;
            }

            if (username.Length == 0 || password.Length == 0)
            {
                Response.Write("<script>alert('用户名密码不能为空!')</script>");
                return;
            }
            if (password != password2)
            {
                Response.Write("<script>alert('请在次确认密码!')</script>");
                TextBox2.Text = "";
                TextBox3.Text = "";
                return;
            }

            string sql2 = "update  tb_user  set password = '" + password + "' where username = '" + username + "' and email = '" + email + "'";
            if (SQLHelper.executeNoQuery(sql2) != 1)
            {
                Response.Write("<script>alert('更新失败!')</script>");
                return;
            }

            Response.Write("<script>alert('更新成功!')</script>");
            Server.Transfer("Login.aspx");
        }
    }
}